import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

//导入持久化依赖包
import VuexPersistence from 'vuex-persist'
//实例化持久化插件对象
const vuexLocal = new VuexPersistence({
  storage: window.sessionStorage,//存储介质,
  key: "vuex",//存储到本地存储
})

export default new Vuex.Store({
  state: {
    token: '', //管理后台的token值
    users: {},
    isLoading:false,
    bread:[], //空面包屑
  },
  mutations: {
    // 管理后台登录成功后，存储用户登录信息
    login(state, obj) {
      state.token = obj.token;
      state.users = obj;
    },
    // 退出  清空token值
    logout(state){
      state.token = '';
      state.users = {}
    },
    // 设置loading效果
    setLoading(state,status){
      state.isLoading = status;
    },
    // 设置面包屑效果
    setBread(state,bread){
      // console.log(bread)
      state.bread = bread;
    },
  },
  actions: {
  },
  modules: {
  },
  plugins: [vuexLocal.plugin]
})
